package au.com.spaceandtime.time;

/**
 * Convert Degrees to hours, mins, seconds and visa-versa.
 * User: whale
 * Date: 20/10/13
 * Time: 2:38 PM
 */
public class HourMinSec {

    int hours = 0;
    int minutes = 0;
    double seconds = 0;

    public HourMinSec(int hours, int minutes, double seconds) {
        this.hours = hours;
        this.minutes = minutes;
        this.seconds = seconds;
    }

    public HourMinSec(double degrees) {

        HourMinSec hms = this.toHourMinSec(degrees);

        hours = hms.getHours();
        minutes = hms.getMinutes();
        seconds = hms.getSeconds();
    }

    public double asDouble() {
        return hours + minutes/60d + seconds/3600d;
    }


    public static HourMinSec toHourMinSec(double decimal) {
        int hours = (int)Math.floor(decimal/15);
        double remainder = decimal/15 - Math.floor(decimal*24/360);

        int minutes = (int)Math.floor(remainder*60);

        remainder = remainder*60 - Math.floor(remainder*60);
        double seconds = remainder*60;

        return new HourMinSec(hours, minutes, seconds);
    }


    public int getHours() {
        return hours;
    }

    public void setHours(int hours) {
        this.hours = hours;
    }

    public int getMinutes() {
        return minutes;
    }

    public void setMinutes(int minutes) {
        this.minutes = minutes;
    }

    public double getSeconds() {
        return seconds;
    }

    public void setSeconds(double seconds) {
        this.seconds = seconds;
    }

}
